//
//  SkeletonConfig.swift
//  Skeleton
//
//  Created by hubin on 2025/7/12.
//

import UIKit

// MARK: - 骨架配置系统
public struct SkeletonConfig {
    
    public var baseZPosition: CGFloat = 1000
    public var depthFactor: CGFloat = 0.8
    
    // 圆角配置
    public var cornerRadius: CGFloat = 4
    
    // 动画-延迟
    public var animationDuration: TimeInterval = 1.5
    public var animationDelayDepthFactor: CGFloat = 0.1
    
    // 基础颜色配置
    public var highlightColor = UIColor(white: 0.97, alpha: 1)
    public var baseColor = UIColor(white: 0.90, alpha: 1)
    
    init() {}
//    // 层级衰减参数
//    public var colorDepthFactor: CGFloat = 0.85   // 每层颜色衰减系数 (0-1)
//    public var cornerRadiusDepthFactor: CGFloat = 0.9  // 每层圆角衰减系数
    
    // 文本骨架配置
    public var skeletonTextEnabled: Bool = true
    public var skeletonLineHeight: CGFloat = 12
    public var skeletonLineSpacing: CGFloat = 8
    public var skeletonMinLineLength: CGFloat = 0.3  // 最小行长度比例 (30%)
    public var skeletonMaxLineLength: CGFloat = 0.9  // 最大行长度比例 (90%)
    public var maxSkeletonLines: Int = 3            // 最多显示3行短线
   
    // 按钮配置
    public var buttonContentMode: UIView.ContentMode = .center
    public var preserveButtonContentInsets: Bool = true
//    
//    // 层级深度（内部使用）
//    internal var depthLevel: Int = 0
//    
//    public init() {}
//    
//    /// 为子视图创建调整后的配置
//    public func configForChild(depthDelta: Int = 1) -> SkeletonConfig {
//        var childConfig = self
//        childConfig.depthLevel = self.depthLevel + depthDelta
//        
//        // 颜色按层级衰减
//        let colorFactor = pow(colorDepthFactor, CGFloat(childConfig.depthLevel))
//        childConfig.baseColor = baseColor.adjustBrightness(factor: colorFactor)
//        childConfig.highlightColor = highlightColor.adjustBrightness(factor: colorFactor)
//        
//        // 圆角按层级衰减
//        childConfig.cornerRadius = cornerRadius * pow(cornerRadiusDepthFactor, CGFloat(childConfig.depthLevel))
//        
//        // 动画延迟增加
//        childConfig.baseAnimationDelay += animationDelayDepthFactor * Double(childConfig.depthLevel)
//        
//        return childConfig
//    }
}

//// MARK: - 颜色扩展
//private extension UIColor {
//    /// 调整颜色亮度
//    func adjustBrightness(factor: CGFloat) -> UIColor {
//        var hue: CGFloat = 0
//        var saturation: CGFloat = 0
//        var brightness: CGFloat = 0
//        var alpha: CGFloat = 0
//        
//        if getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha) {
//            let newBrightness = max(0, min(1, brightness * factor))
//            return UIColor(hue: hue, saturation: saturation, brightness: newBrightness, alpha: alpha)
//        }
//        
//        // 无法获取HSB值时使用RGB调整
//        var red: CGFloat = 0
//        var green: CGFloat = 0
//        var blue: CGFloat = 0
//        
//        if getRed(&red, green: &green, blue: &blue, alpha: &alpha) {
//            let adjustment = (factor - 1.0) / 2.0
//            return UIColor(
//                red: max(0, min(1, red + adjustment)),
//                green: max(0, min(1, green + adjustment)),
//                blue: max(0, min(1, blue + adjustment)),
//                alpha: alpha
//            )
//        }
//        
//        return self
//    }
//}

